package com.xindz.cn.mvptest.components.product.view;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.avos.avoscloud.AVException;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.xindz.cn.mvptest.R;
import com.xindz.cn.mvptest.base.BaseActivity;
import com.xindz.cn.mvptest.components.product.data.AttachProductBean;
import com.xindz.cn.mvptest.components.product.persenter.ProductAddPersenter;

import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @name MvpTest
 * @class name：com.xindz.cn.mvptest.components.product.view
 * @describe 添加一件商品
 * @anthor XINDZ
 * @time 2017/10/30 17:47
 * @change
 * @chang time
 * @class describe
 */
public class ProductAddActivity extends BaseActivity<ProductAddView, ProductAddPersenter> implements ProductAddView {
    @BindView(R.id.et_product_title)
    TextInputEditText etProductTitle;
    @BindView(R.id.et_product_description)
    TextInputEditText etProductDescription;
    @BindView(R.id.et_product_xindz)
    TextInputEditText etProductXindz;
    @BindView(R.id.et_product_price)
    TextInputEditText etProductPrice;
    @BindView(R.id.bt_product_add)
    Button btProductAdd;
    @BindView(R.id.et_product_image)
    TextInputEditText etProductImage;
    private String des;
    private String title;
    private String xindz;
    private Integer price;
    private String imageName;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_add);
        ButterKnife.bind(this);

    }

    @Override
    public ProductAddPersenter createPresneter() {
        return new ProductAddPersenter();
    }

    @Override
    public ProductAddView createView() {
        return this;
    }


    @OnClick(R.id.bt_product_add)
    public void onViewClicked() {
        getData();
        AttachProductBean attachProductBean = new AttachProductBean();
        attachProductBean.setTitle("这是附件");
        long l = System.currentTimeMillis();
        Date date = new Date(l);
        attachProductBean.setCedate(date);
        getPresneter().addProduct(attachProductBean,title, des, imageName, xindz, price);
    }

    private void getData() {
        des = etProductDescription.getEditableText().toString();
        title = etProductTitle.getEditableText().toString();
        xindz = etProductXindz.getEditableText().toString();
        imageName = etProductImage.getEditableText().toString();
        price = 100;
    }

    @Override
    public void add(AVException e) {
        if (e == null) {
            ToastUtils.showShort("添加成功");
        } else {
            ToastUtils.showShort("添加失败" + e.getMessage());
        }

    }
}
